﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Omes.Services;

namespace FashionMural.Web
{
    public partial class Main : System.Web.UI.MasterPage
    {
        public List<Omes.Model.Page> ProductPage { set; get; }
        public List<Omes.Model.Page> ServerPage { set; get; }
        public List<Omes.Model.Page> AboutPage { set; get; }
        public List<Omes.Model.Page> BusinessPage { set; get; }
        public List<Omes.Model.FriendLink> FirendLinks { set; get; }
        public List<Omes.Model.ImageList> ADImages { set; get; }
        public Omes.Model.PageInfo PageInfo { set; get; }
        private Omes.Services.IPageService pageservice;
        private Omes.Services.PageInfoService pageinfoservice;
        private Omes.Services.IResourceService resourceservice;
        public int ProductWidth { set; get; }
        public int ServerWidth { set; get; }
        public string LeaveMessage{set;get;}

        protected void Page_Load(object sender, EventArgs e)
        {
            ADImages = new List<Omes.Model.ImageList>();
            resourceservice = new ResourceService();
            pageinfoservice = new Omes.Services.PageInfoService();

            FirendLinks = pageinfoservice.GetFriendLinks();

            var ads = resourceservice.GetAds();
            if (ads != null)
            {
                ADImages.AddRange(ads);
            }
            PageInfo = pageinfoservice.GetPageInfo()??new  Omes.Model.PageInfo();
            metad.Attributes["content"] = PageInfo.Meta;
            descmeata.Attributes["content"] = PageInfo.MetaDescribe;
            pageservice = new Omes.Services.PageService();
            ProductPage = new List<Omes.Model.Page>();
            int pid = int.Parse(System.Configuration.ConfigurationManager.AppSettings["cpzx"]);
            ProductPage = pageservice.GetChildPage(pid);
            int sid = int.Parse(System.Configuration.ConfigurationManager.AppSettings["fwxm"]);
            ServerPage = pageservice.GetChildPage(sid);
            if (ServerPage != null)
            {
                ServerWidth = ServerPage.Count * 40 + 12 * ServerPage.Sum(i => i.PageName.Length);
            }
            if (ProductPage != null)
            {
                ProductWidth = ProductPage.Count * 40 + 12 * ProductPage.Sum(i => i.PageName.Length);
            }
        }

        protected void CheckLMIn_Click(object sender, EventArgs e)
        {
            Omes.Services.DbServer db = new DbServer();
            int lid = db.AddLeaveMessage(OneUserName.Text, Others.Text, DateTime.Now.ToString(),
                                         ContactOperate.Text, 1);
            if (lid>0)
            {
                LeaveMessage = "留言成功！";
              
            }else
            {
                 LeaveMessage="留言失败！";
            }
        }
    }
}